﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="goods_edit.aspx.cs" Inherits="SF.Ucenter.admin.goods.goods_edit" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <title>编辑商品</title>
    <link href="../../scripts/artdialog/ui-dialog.css" rel="stylesheet" type="text/css" />
    <link href="../skin/default/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" charset="utf-8" src="../../scripts/jquery/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../scripts/jquery/Validform_v5.3.2_min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../scripts/datepicker/WdatePicker.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../scripts/artdialog/dialog-plus-min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../scripts/webuploader/webuploader.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../editor/kindeditor-min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/uploader.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/laymain.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/common.js"></script>
    <style type="text/css">
        .showimgs {
            padding-top:5px;
        }
    </style>
    <script type="text/javascript">
        var amountslist = "";
        $(function () {
            //初始化表单验证
            $("#form1").initValidform();

            //初始化编辑器
            var editor = KindEditor.create('.editor', {
                width: '98%',
                height: '350px',
                resizeType: 1,
                uploadJson: '../../tools/upload_ajax.ashx?action=EditorFile&IsWater=1',
                fileManagerJson: '../../tools/upload_ajax.ashx?action=ManagerFile',
                allowFileManager: true
            });
            var editorMini = KindEditor.create('.editor-mini', {
                width: '98%',
                height: '250px',
                resizeType: 1,
                uploadJson: '../../tools/upload_ajax.ashx?action=EditorFile&IsWater=1',
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link']
            });
            //初始化上传控件[封面图片]
            $(".upload-img").each(function () {
                $(this).InitUploader({ filesize: "10240", sendurl: "../../tools/upload_ajax.ashx", swf: "../../scripts/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp,rar,zip,doc,xls,txt" });
            });
            $(".upload-album").each(function () {
                $(this).InitUploader({ btntext: "批量上传", btnwidth: 66, multiple: true, water: true, thumbnail: true, filesize: "2048", sendurl: "../../tools/upload_ajax.ashx", swf: "../../scripts/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp" });
            });
            $(".attach-btn").click(function () {
                showAttachDialog();
            });
            //设置封面图片的样式
            $(".photo-list ul li .img-box img").each(function () {
                if ($(this).attr("src") == $("#hidFocusPhoto").val()) {
                    $(this).parent().addClass("selected");
                }
            });
        });

        function editset(obj, id) {
            setamountslist(obj);
            showLine(id);
        }

        //设置 库存集合的值
        function setamountslist(obj) {
            amountslist = obj;
        }
        //获取当前选中的尺寸id
        function getsize() {
            var sizeid;
            var sizes = $("#rblSize").children("input[type='radio']");
            for (var i = 0; i < sizes.length; i++) {
                if ($(sizes[i]).attr("checked") != null && $(sizes[i]).attr("checked") != "") {
                    sizeid = $(sizes[i]).attr("value");
                }
            }
            return sizeid;
        }
        //选中 库存 输入  相应颜色选中
        function selectColor(obj) {
            var index = $(obj).attr("id");
            var colorsselect = $("#rblColor").parent().children(".boxwrap").children("a");
            for (var i = 0; i < colorsselect.length; i++) {
                $(colorsselect[i]).removeClass("selected");
                if (index == i) {
                    $(colorsselect[i]).addClass("selected");
                }
            }
        }

        //尺码选中
        function checkColorSize(obj) {
            if (obj != null && obj != "") {
                var as = $(obj).parent();
                for (var i = 0; i < as.children("a").length; i++) {
                    $(as.children("a")[i]).removeClass("selected");
                    if ($(obj).attr("id") == i) {
                        $(as.children("a")[i]).addClass("selected");
                    }
                }
                var inps = $(as.parent().children()[1]).children("input");
                for (var i = 0; i < inps.length; i++) {
                    if ($(obj).attr("id") == i) {
                        $(inps[i]).attr("checked", "true");
                    } else {
                        $(inps[i]).removeAttr("checked");
                    }
                }
                //变更 库存列表 及 库存input值
                var lists = amountslist.split(",");
                var sizeid = getsize();
                var showlist = $("#dlamountList .boxwrap").children("input");
                for (var i = 0; i < showlist.length; i++) {
                    $(showlist[i]).val("");
                }
                for (var i = 0; i < lists.length; i++) {
                    if (lists[i].indexOf(sizeid + "^") >= 0) {
                        var s = lists[i].split("_");
                        var ss = s[0].split("^");
                        $(showlist[ss[1]]).val(s[2]);
                    }
                }
            }
        }
        //暂存 库存列表
        function saveamounts(obj) {
            var sizeid = getsize();
            var text = parseInt($(obj).val()).toString();
            if (text == "NaN") {
                text = 0;
            }
            var amount = text;
            $(obj).val(amount);
            var colors = $("#rblColor").children("input[type='radio']");
            var colorid = $(colors[$(obj).attr("id")]).attr("value");
            var lists = amountslist.split(",");
            amountslist = "";
            for (var i = 0; i < lists.length-1; i++) {
                if (lists[i] != "" && lists[i].indexOf(sizeid + "^" + $(obj).attr("id") + "_") < 0) {
                    amountslist += lists[i] + ",";
                }
            }
            if (amount != "0" && amount != "") {
                amountslist += sizeid + "^" + $(obj).attr("id") + "_" + colorid + "_" + amount + ",";
            }
            $("#hiddenLists").attr("value", amountslist);
        }
        //存入 库存集合
        var allowSubmit = false;
        function savelist() {
            var ty = $("#dlGoodsTypeId").children("dd").children("div").children("div").children("a").children("span").text();
            if (ty != "单品") {
                saveamounts(0);
                var obj = $("#txtGoodsNum").val();
                var lists = $("#hiddenLists").val();
                if (allowSubmit == false) {
                    $.get("/tools/goods_ajax.ashx", { action: "save_amountlist", goodsNum: obj, str: lists, time: new Date().getTime() }, function (res) {
                        allowSubmit = true;
                        $("#btnSubmit").click();
                    });
                }
                return allowSubmit;
            } else {
                return true;
            }
        }
        //属性栏 控制
        function showLine(obj) {
            if (obj == "clothes" || obj == "trousers" || obj == "shoes") {
                $.get("/tools/goods_ajax.ashx", { action: "get_color_size", id: obj,time:new Date().getTime() }, function (res) {
                    //根据返回数据 添加标签
                    if (res != "") {
                        var temp = res.split("|");
                        var sizes = temp[0].substring(0, temp[0].length - 1).split(",");
                        var colors = temp[1].substring(0, temp[1].length - 1).split(",");
                        for (var i = 0; i < sizes.length; i++) {
                            var strc = i == 0 ? " checked='true'" : "";
                            var stra = i == 0 ? " class='selected'" : "";
                            var size = sizes[i].split("_");
                            $("#rblSize").append("<input id='" + i + "' name='rblSize' type='radio' value='" + size[0] + "' " + strc + " /><label>" + size[1] + "</label>");
                            $("#rblSize").parent().children(".boxwrap").append("<a id='" + i + "' href='#' onclick='checkColorSize(this)' " + stra + ">" + size[1] + "</a>");
                        }
                        for (var i = 0; i < colors.length; i++) {
                            var color = colors[i].split("_");
                            $("#rblColor").append("<input id='" + color[2] + "' name='rblColor' type='radio' value='" + color[0] + "' /><label>" + color[1] + "</label>");
                            $("#rblColor").parent().children(".boxwrap").append("<a id='" + i + "'>" + color[1] + "</a>");
                            $("#dlamountList .boxwrap").append("<input id='" + i + "' type='text' class='input small' onblur='saveamounts(this)' onfocus='selectColor(this)' />");
                        }
                        var as = $("#rblSize").parent().children(".boxwrap").children("a");
                        checkColorSize(as[0]);
                        //需要显示的属性
                        $("#dlCategoryId").css("display", "block");
                        $("#dlrblStatus").css("display", "block");
                        $("#dlrblSize").css("display", "block");
                        $("#dlrblColor").css("display", "block");
                        $("#dlamountList").css("display", "block");
                        $("#div_stock_quantity").css("display", "block");
                        $("#div_market_price").css("display", "block");
                        $("#div_sell_price").css("display", "block");
                        $("#div_get_price").css("display", "block");
                        $("#dltxtSortId").css("display", "block");
                        //每种类型都需 加上这句-- 删除撑开的位置
                        $("dl").remove("#autodl");
                    } else {
                        var winDialog = top.dialog({
                            title: '商品提示',
                            content: '请在商品分类处配置此类别商品的属性！',
                            okValue: '确定'
                        }).show(winDialog);
                        return;
                    }
                });
            } else if (obj == "maquillage") {
                setTimeout(function () {
                    //需要显示的属性
                    $("#dlCategoryId").css("display", "block");
                    $("#dlrblStatus").css("display", "block");
                    $("#div_stock_quantity").css("display", "block");
                    $("#div_market_price").css("display", "block");
                    $("#div_sell_price").css("display", "block");
                    $("#div_get_price").css("display", "block");
                    $("#dltxtSortId").css("display", "block");
                    $("#dlamountNum").css("display", "block");
                    //每种类型都需 加上这句-- 删除撑开的位置
                    $("dl").remove("#autodl");
                },1500);
            }
        }
    </script>
</head>
<body class="mainbody">
    <form id="form1" runat="server">
        <!--导航栏-->
        <div class="location">
            <a href="goods_list.aspx" class="back"><i></i><span>返回列表页</span></a>
            <a href="../First.aspx" class="home"><i></i><span>首页</span></a>
            <i class="arrow"></i>
            <a href="goods_list.aspx"><span>商品管理</span></a>
            <i class="arrow"></i>
            <span>编辑信息</span>
        </div>
        <div class="line10"></div>
        <!--/导航栏-->

        <!--商品-->
        <div id="floatHead" class="content-tab-wrap">
            <div class="content-tab">
                <div class="content-tab-ul-wrap">
                    <ul>
                        <li><a href="javascript:;" class="selected">基本信息</a></li>
                        <li><a href="javascript:;" >图片信息</a></li>
                        <li><a href="javascript:;" >详细描述</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <asp:HiddenField ID="hiddenLists" runat="server" />
        <div class="tab-content">
            <dl id="dlGoodsTypeId">
                <dt>所属类型</dt>
                <dd>
                    <div class="rule-single-select">
                        <asp:DropDownList ID="ddlGoodsTypeId" runat="server" datatype="*" sucmsg=" " AutoPostBack="true" OnSelectedIndexChanged="ddlGoodsTypeId_SelectedIndexChanged"></asp:DropDownList>
                    </div>
                </dd>
            </dl>
            <dl id="dlCategoryId" style="display:none">
                <dt>所属类别</dt>
                <dd>
                    <div class="rule-single-select">
                        <asp:DropDownList ID="ddlCategoryId" runat="server" datatype="*" sucmsg=" "></asp:DropDownList>
                    </div>
                </dd>
            </dl>
            <dl id="dltxtGoodsNum" style="display:block">
                <dt>商品编号</dt>
                <dd>
                    <asp:TextBox ID="txtGoodsNum" runat="server"  CssClass="input normal" datatype="*1-50" sucmsg=" "></asp:TextBox>
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl id="dltxtName" style="display:block">
                <dt>商品名称</dt>
                <dd>
                    <asp:TextBox ID="txtName" runat="server" CssClass="input normal" datatype="*2-100" sucmsg=" " />
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl id="dlrblStatus" style="display:none">
                <dt>商品类型</dt>
                <dd>
                    <div class="rule-multi-radio">
                        <span id="rblStatus">
                            <asp:RadioButton ID="rblStatus_0" GroupName="rblStatus" runat="server" Checked="true" />
                            <label for="rblStatus_0">新品上架</label>
                            <asp:RadioButton ID="rblStatus_1" GroupName="rblStatus"  runat="server" />
                            <label for="rblStatus_1">精选商品</label>
                            <asp:RadioButton ID="rblStatus_2" GroupName="rblStatus"  runat="server"  />
                            <label for="">特惠商品</label>
                        </span>
                    </div>
                    <span class="Validform_checktip">*选择商品类型</span>
                </dd>
            </dl>
            
            <dl id="dlrblSize" style="display:none">
                <dt>商品尺码</dt>
                <dd>
                    <div class="rule-multi-radio">
                        <span id="rblSize"></span>
                    </div>
                    <span class="Validform_checktip">*商品尺码</span>
                </dd>
            </dl>
            <dl id="dlrblColor" style="display:none">
                <dt>商品颜色</dt>
                <dd>
                    <div class="rule-multi-radio">
                        <span id="rblColor"></span>
                    </div>
                    <span class="Validform_checktip">*商品颜色</span>
                </dd>
            </dl>
            <dl id="dlamountList" style="display:none">
                <dt>当前尺码库存</dt>
                <dd>
                    <div class="rule-multi-radio">
                    </div>
                </dd>
            </dl>
            
            <dl id="dlamountNum" style="display:none;">
                <dt>商品库存</dt>
                <dd>
                    <asp:TextBox ID="amountNum" runat="server"  CssClass="input small" Text="0"></asp:TextBox>
                </dd>
            </dl>
            <dl id="div_market_price" runat="server" style="display:none">
                <dt>
                    <asp:Label ID="div_market_price_title" runat="server" Text="成本价格" /></dt>
                <dd>
                    <asp:TextBox ID="field_control_market_price" runat="server" CssClass="input small" datatype="/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/" sucmsg=" ">0</asp:TextBox>
                    元
                    <asp:Label ID="div_market_price_tip" runat="server" CssClass="Validform_checktip" />
                </dd>
            </dl>
            <dl id="div_sell_price" runat="server" style="display:none">
                <dt>
                    <asp:Label ID="div_sell_price_title" runat="server" Text="销售价格" /></dt>
                <dd>
                    <asp:TextBox ID="field_control_sell_price" runat="server" CssClass="input small" datatype="/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/" sucmsg=" ">0</asp:TextBox>
                    元
                    <asp:Label ID="div_sell_price_tip" runat="server" CssClass="Validform_checktip" />
                </dd>
            </dl>
            <dl id="div_get_price" runat="server" style="display:none">
                <dt>
                    <asp:Label ID="div_get_price_title" runat="server" Text="展示划价" /></dt>
                <dd>
                    <asp:TextBox ID="field_control_get_price" runat="server" CssClass="input small" datatype="/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/" sucmsg=" ">0</asp:TextBox>
                    元
                    <asp:Label ID="Label3" runat="server" CssClass="Validform_checktip" />
                </dd>
            </dl>
            <%--<dl id="div_valid_time" runat="server" style="display:none">
                <dt>
                    <asp:Label ID="Label1" runat="server" Text="有效期" /></dt>
                <dd>
                    <asp:TextBox ID="txtValidTime" runat="server" CssClass="input small" datatype="n" sucmsg=" "></asp:TextBox>
                    <asp:Label ID="div_valid_time_tip" runat="server" CssClass="Validform_checktip" />
                </dd>
            </dl>--%>
            <dl id="dltxtSortId" style="display:none">
                <dt>排序数字</dt>
                <dd>
                    <asp:TextBox ID="txtSortId" runat="server" CssClass="input small" datatype="n" sucmsg=" ">99</asp:TextBox>
                    <span class="Validform_checktip">*数字，越小越向前</span>
                </dd>
            </dl>
            
            <dl id="autodl" style="height:200px;"></dl>
        </div>

        <div class="tab-content" style="display: none">
            <dl>
                <dt>封面图片</dt>
                <dd>
                    <asp:TextBox ID="txtImgUrl" runat="server" CssClass="input normal upload-path" ReadOnly="true" />
                    <div class="upload-box upload-img"></div>
                    <br />
                        <asp:Image ID="imgHeadPic" CssClass="showimgs" runat="server" Width="200px" Height="200px" />
                    
                </dd>
            </dl>
            <dl id="div_albums_container" runat="server">
                <dt>图片相册</dt>
                <dd>
                    <div class="upload-box upload-album"></div>
                    <input type="hidden" name="hidFocusPhoto" id="hidFocusPhoto" runat="server" class="focus-photo" />
                    <div class="photo-list">
                        <ul>
                            <asp:Repeater ID="rptAlbumList" runat="server">
                                <ItemTemplate>
                                    <li>
                                      <input type="hidden" name="hid_photo_name" value="<%#Eval("id")%>|<%#Eval("imgUri")%>" />
                                      <input type="hidden" name="hid_photo_remark" value="<%#Eval("imgName")%>" />
                                      <div class="img-box" onclick="setFocusImg(this);">
                                        <img alt="" src="<%#Eval("imgUri")%>"  />
                                        <span class="remark"><i><%#Eval("imgName").ToString() == "" ? "暂无描述..." : Eval("imgName").ToString()%></i></span>
                                      </div>
                                      <a href="javascript:;" onclick="setRemark(this);">描述</a>
                                      <a href="javascript:;" onclick="delImg(this);">删除</a>
                                    </li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                    </div>
                </dd>
            </dl>

            </div>

        <div class="tab-content" style="display: none">
            <dl>
                <dt>品牌名称</dt>
                <dd>
                    <asp:TextBox ID="txtBrandName" runat="server" CssClass="input normal" datatype="*0-100" sucmsg=" " />
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl>
                <dt>产地</dt>
                <dd>
                    <asp:TextBox ID="txtPlace" runat="server" CssClass="input normal" datatype="*0-100" sucmsg=" " />
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl>
                <dt>单位</dt>
                <dd>
                    <asp:TextBox ID="txtUnit" runat="server" CssClass="input normal" datatype="*0-100" sucmsg=" " />
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl>
                <dt>适合人群</dt>
                <dd>
                    <asp:TextBox ID="txtSuitPerson" runat="server" CssClass="input normal" datatype="*0-100" sucmsg=" " />
                    <span class="Validform_checktip">*最多50个字符</span>
                </dd>
            </dl>
            <dl>
                <dt>上市年月</dt>
                <dd>
                    <div class="input-date">
                        <asp:TextBox ID="txtAddTime" ReadOnly="true" runat="server"
                             CssClass="input date" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"  errormsg="请选择正确的日期" sucmsg=" " />
                        <i>日期</i>
                    </div>
                    <span class="Validform_checktip">不选择默认当前年月</span>
                </dd>
            </dl>
        </div>

        
        <!--/商品-->

        <!--工具栏-->
        <div class="page-footer">
            <div class="btn-list">
                <asp:Button ID="btnSubmit" runat="server" Text="提交保存" CssClass="btn" OnClick="btnSubmit_Click" OnClientClick="return savelist();" />
                <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript: history.back(-1);" />
            </div>
            <div class="clear"></div>
        </div>
        <!--/工具栏-->
    </form>
</body>
</html>
